<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
		<title>External Vendor Page</title>
		<link rel="stylesheet" href="../../css/styles.css" type="text/css" />
		<script type="text/javascript" src="js/validation.js"></script>
	</head>
	<script type="text/javascript">
	  function showEnterForm(){
	      document.getElementById("enterDiv").style.display = "block";
	      document.getElementById("viewDiv").style.display = "none";
	  }
	  
	  function showSearchForm(){
	      document.getElementById("enterDiv").style.display = "none";
	      document.getElementById("viewDiv").style.display = "block";
	  }
	  
	  function setDisplay(){
	     var getDetailsField = document.getElementById("getDetailsField");
	     var saveDetailsField = document.getElementById("saveDetailsField");
	     if(getDetailsField != null){
	        showSearchForm();
	     }else if(saveDetailsField != null){
	       showEnterForm();
	     }
	  }
	  function validateFormOnSubmit(theForm) {
		var reason = "";
		
		reason += validateName(theForm.vendorName);
		/* reason += validateAddressLine(theForm.vendorAddress1);
		reason += validateAddressLine(theForm.vendorAddress2); */
		reason += validateCity(theForm.vendorCity);
		reason += validateCountry(theForm.vendorCountry);
		reason += validatePin(theForm.vendorPin);
		reason += validatePhone(theForm.vendorPhone);
		reason += validateEmail(theForm.vendorEmail);
		if (reason != "") {
	    alert("Some fields need correction:\n" + reason);
	    return false;
	  }
	 return true;
	}
	function validateFormOnSearch(theForm){
		var reason = "";
		
		reason +=validateOptionEmpty(theForm.vidSearch,theForm.vnameSearch);
		if (reason !=""){
		alert("Error Message:\n" + reason);
		return false;
		}
		return true;
	}
	</script>
	<body onload="javascript:setDisplay();">
		<div id="container">
			<jsp:include page="/jsp/menu.jsp" />
			<div style="height:420px;">
		  		<div class="path">
					<br><a href="home.htm"> Home </a>-&gt;
					<a> Account </a>-&gt;
					<a> Purchase </a>-&gt;
					<a href="vendor.htm"> External Vendor </a>
		  		</div>
		  		<div class="leftDiv">
		   			<b>External Vendor Details</b><br><br>
					<fieldset style="height:80px; width:200px;background: #FFF;">
						<table cellpadding=20>
							<tr>
								<td>
									<a href="javascript:showSearchForm()">
				                        	View Vendor Details
									</a>
								</td>
							</tr>
							<tr>
								<td>
				                 	<a href="javascript:showEnterForm()">
				                        	Enter Vendor Details
				                 	</a>
								</td>
							</tr>
					</table>
				</fieldset>
		  	</div>
		</div>
		<form:form method="POST" action="getVendorDetails.htm" commandName="vendorDetails" onsubmit="return validateFormOnSearch(this)">
		 	<div id="viewDiv" class="maininfo" style="display: none">
			 	<div class="lable">
						Vendor Details
				</div>
			 	<div id="searchForm">
					<table>
						<tr>
							<th>Enter Vendor ID</th>
							<td><form:input path="vidSearch" /></td>
						</tr>
						<tr>
							<th>Enter Vendor Name</th>
							<td><form:input path="vnameSearch" /></td>
						</tr>
						<tr>
							<th></th>
							<td><input type="submit" value="Search" size=5></td>
						</tr>
					</table>
				</div>
				<c:if test="${!empty model.bList}">
				<div id="viewTable" >
					<table cellpadding="10">
						<tr>
							<th>Vendor ID</th>
							<th>Vendor Name</th>
							<th>Vendor Address</th>
							<th>Vendor Phone</th>
						</tr>
						<c:forEach items="${model.bList}" var="vendor">
						<tr>
							<td><c:out value="${vendor.numVendorId}"></c:out></td>
							<td><c:out value="${vendor.strVendorName}"></c:out></td>
							<td><c:out value="${vendor.strVendorAddress}"></c:out></td>
							<td><c:out value="${vendor.strVendorPhone}"></c:out></td>
						</tr>
						</c:forEach> 
					</table>
				</div>
				</c:if>
		 	</div>
		 </form:form>
		 <form:form method="POST" action="saveVendorDetails.htm" commandName="vendorDetails" onsubmit="return validateFormOnSubmit(this)" >
		 	<div id="enterDiv" class="maininfo" style="display: none">
				<div class ="lable">
					Enter Vendor Details
						<c:if test="${model.isSave}">
							<div id="result"><c:out value="Submitted Successfully"></c:out></div>
						</c:if>
				</div>
				<div id="infoDiv" style="margin-top: 10px;">
					<table>
						<tr>
							<th>Name <span class="mand-star">* </span></th>
							<td><form:input path="vendorName"></form:input></td>
						</tr>
						<tr>
							<th>Address Line1 </th>
							<td><form:input path="vendorAddress1"></form:input></td>
						</tr>
						<tr>
							<th>Address Line2 </th>
							<td><form:input path="vendorAddress2"></form:input></td>
						</tr>
						<tr>
							<th>City <span class="mand-star">* </span></th>
							<td><form:input path="vendorCity"></form:input></td>
						</tr>
						<tr>
							<th>Country <span class="mand-star">* </span></th>
							<td><form:input path="vendorCountry"></form:input></td>
						</tr>
						<tr>
							<th>PIN No. <span class="mand-star">* </span></th>
							<td><form:input path="vendorPin" maxlength="6"></form:input></td>
						</tr>
						<tr>
							<th>Contact No.<span class="mand-star">* </span></th>
							<td><form:input path="vendorPhone" maxlength="11" ></form:input></td>
						</tr>
						<tr>
							<th>Email Address </th>
							<td><form:input path="vendorEmail"></form:input></td>
						</tr>
						<tr>
							<th></th>
							<td><input type="submit" value="Submit"></td>
						</tr>
					</table>
				</div>
			</div>
		</form:form>
		<c:if test="${model.isGet}">
		   	<input id="getDetailsField" type="hidden" name="getDetailsField"/>  
		</c:if>
		<c:if test="${model.isSave}">
		   <input id="saveDetailsField" type="hidden" name="saveDetailsField"/>  
		</c:if>	
		<div id="footer">
		<jsp:include page="/jsp/footer.jsp" />
		</div>
	</body>
</html>
